#include<reg52.h>
#define JZ P1
#define SMG P0
char smg_code[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
				0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay_us(unsigned int time)
{
	while(time--);
}

int JZ_code()
{
	int ret = 0;
	JZ = 0xf7;
	delay_us(150);
	if(JZ != 0xf7)
	{
		switch(JZ)
		{
			case 0x77: ret = 1; break;
			case 0xb7: ret = 2; break;
			case 0xd7: ret = 3; break;
			case 0xe7: ret = 4; break;
		}
	}
	JZ = 0xfb;
	delay_us(150);
	if(JZ != 0xfb)
	{
		switch(JZ)
		{
			case 0x7b: ret = 5; break;
			case 0xbb: ret = 6; break;
			case 0xdb: ret = 7; break;
			case 0xeb: ret = 8; break;
		}
	}
	JZ = 0xfd;
	delay_us(150);
	if(JZ != 0xfd)
	{
		switch(JZ)
		{
			case 0x7d: ret = 9; break;
			case 0xbd: ret = 10; break;
			case 0xdd: ret = 11; break;
			case 0xed: ret = 12; break;
		}
	}
	JZ = 0xfe;
	delay_us(150);
	if(JZ != 0xfe)
	{
		switch(JZ)
		{
			case 0x7e: ret = 13; break;
			case 0xbe: ret = 14; break;
			case 0xde: ret = 15; break;
			case 0xee: ret = 16; break;
		}
	}
	return ret;
}
void main()
{

	while(1)
	{
			int ret = JZ_code();
			SMG = smg_code[ret];
	}
}